package com.bdqn.springweb.filter;

//public class AuthorizationFilter implements Filter {
//    @Override
//    public void init(FilterConfig filterConfig) throws ServletException {
//        @Override
//        public void destroy () {
//        }
//        @Override
//        public void doFilter (ServletRequest request, ServletResponse response, FilterChain chain)throw
//                IOException,ServletException {
//            HttpServletRequest httpRequest = (HttpServletRequest) request;
//            HttpServletResponse httpResponse = (HttpServletResponse) response;
//            if (httpRequest.getSession().getAttribute("loginUser") == null) {
//                httpResponse.setContentType("text/html;charset=utf-8");
//                PrintWriter out = httpResponse.getWriter();
//                out.print("<scrinpt>alert('请先进行登录，再进行后续操作！(filter 控制)');location.href='" + httpRequest.getContextPath() + "/login.jsp'</scrinpt>");
//            } else {
//                chain.doFilter(HttpRequest, httpResponse);
//            }
//        }
//    }
//
//    public void init(FilterConfig filterConfig) throws ServletException {
//    }
//
//    @Override
//    public void doFilter(ServletRequest request, ServletResponse response, FilterChain chain)
//            throws IOException, ServletException {
//        HttpServletRequest httpRequest = (HttpServletRequest) request;
//        HttpServletResponse httpResponse = (HttpServletResponse) response;
//
//        if (httpRequest.getSession().getAttribute("loginUser") == null) {
//            httpResponse.setContentType("text/html;charset=utf-8");
//            httpResponse.setStatus(HttpServletResponse.SC_FOUND);
//            httpResponse.setHeader("Location", httpRequest.getContextPath() + "/login.jsp");
//
//        } else {
//            chain.doFilter(request, response);
//        }
//    }
//
//    @Override
//    public void destroy() {
//    }
//}